home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / packages / pending-del.el.z / pending-del.el
Encoding:
Text File  |  1998-05-21  |  5.3 KB  |  166 lines

  1. ;; pending-del.el --- Making insertions replace any selected text.
  2.  
  3. ;; Copyright (C) 1992, 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Matthieu Devin <devin@lucid.com>, 14 Jul 92.
  6. ;; Maintainer: Hrvoje Niksic <hniksic@srce.hr>
  7. ;; Version 2.2
  8.  
  9. ;; This file is part of XEmacs.
  10.  
  11. ;; XEmacs is free software; you can redistribute it and/or modify it
  12. ;; under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 2, or (at your option)
  14. ;; any later version.
  15.  
  16. ;; XEmacs is distributed in the hope that it will be useful, but
  17. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19. ;; General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with XEmacs; see the file COPYING.  If not, write to the 
  23. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. ;; Boston, MA 02111-1307, USA.
  25.  
  26. ;;; Synched up with: 19.34  (distributed as delsel.el in FSF)
  27.  
  28. ;;; Commentary:
  29.  
  30. ;; Much of this code was revamped by Hrvoje Niksic, July 1997, with
  31. ;; version number set to 2.x.
  32.  
  33. ;; Pending-del is now a minor mode, with all the normal toggle
  34. ;; functions.  It should be somewhat faster, too.
  35.  
  36.  
  37. ;;; Code:
  38.  
  39. (defcustom pending-delete-mode nil
  40.   "Non-nil when Pending Delete mode is enabled.
  41. In Pending Delete mode, typed text replaces the selected region."
  42.   :type 'boolean
  43.   :set (lambda (symbol value)
  44.      (pending-delete-mode (or value 0)))
  45.   :initialize 'custom-initialize-default
  46.   :require 'pending-del
  47.   :group 'keyboard)
  48.  
  49. (defcustom pending-delete-modeline-string " PenDel"
  50.   "*String to display in the modeline when Pending Delete mode is active."
  51.   :type 'string
  52.   :group 'keyboard)
  53.  
  54. (add-minor-mode 'pending-delete-mode 'pending-delete-modeline-string)
  55.  
  56.  
  57. (defun pending-delete-active-region (&optional killp)
  58.   (when (and (region-active-p)
  59.          (eq (extent-object zmacs-region-extent) (current-buffer))
  60.          (not buffer-read-only))
  61.     ;; Here we used to check whether the point lies between the
  62.     ;; beginning and end of the extent.  I don't see how it is
  63.     ;; necessary, as the C code makes sure that this is so; it only
  64.     ;; slow things down.
  65.     (if killp
  66.     (kill-region (region-beginning) (region-end))
  67.       (delete-region (region-beginning) (region-end)))
  68.     (zmacs-deactivate-region)
  69.     t))
  70.  
  71. (defun pending-delete-pre-hook ()
  72.   (condition-case e
  73.       (let ((type (and (symbolp this-command)
  74.                (get this-command 'pending-delete))))
  75.     (cond ((eq type 'kill)
  76.            (pending-delete-active-region t))
  77.           ((eq type 'supersede)
  78.            (if (pending-delete-active-region ())
  79.            (setq this-command (lambda () (interactive)))))
  80.           (type
  81.            (pending-delete-active-region ()))))
  82.     (error
  83.      (warn "Error caught in `pending-delete-pre-hook': %s"
  84.        (error-message-string e)))))
  85.  
  86.  
  87. (put 'self-insert-command 'pending-delete t)
  88.  
  89. (put 'yank 'pending-delete t)
  90. (put 'x-yank-clipboard-selection 'pending-delete t)
  91. (put 'toolbar-paste 'pending-delete t)
  92.  
  93. (put 'delete-backward-char 'pending-delete 'supersede)
  94. (put 'backward-delete-char-untabify 'pending-delete 'supersede)
  95. (put 'delete-char 'pending-delete 'supersede)
  96. (put 'c-electric-delete 'pending-delete 'supersede)
  97.  
  98. ;; Support the XEmacs 20.3 'delete functions
  99.  
  100. (put 'backward-or-forward-delete-char 'pending-delete 'supersede)
  101. (put 'cperl-electric-backspace 'pending-delete 'supersede)
  102. (put 'cperl-electric-delete 'pending-delete 'supersede)
  103.  
  104. ;; Don't delete for these.  They're more problematic than helpful.
  105. ;;
  106. ;; (put 'newline-and-indent 'pending-delete t)
  107. ;; (put 'newline 'pending-delete t)
  108. ;; (put 'open-line 'pending-delete t)
  109.  
  110. (put 'insert-register 'pending-delete t)
  111.  
  112.  
  113. ;;;###autoload
  114. (defun turn-on-pending-delete (&optional ignored)
  115.   "Turn on pending delete minor mode unconditionally."
  116.   (interactive)
  117.   (pending-delete-mode 1))
  118.  
  119. ;;;###autoload
  120. (defun turn-off-pending-delete (&optional ignored)
  121.   "Turn off pending delete minor mode unconditionally."
  122.   (interactive)
  123.   (pending-delete-mode 0))
  124.  
  125. ;;;###autoload
  126. (defun pending-delete-mode (&optional arg)
  127.   "Toggle Pending Delete minor mode.
  128. When the pending delete is on, typed text replaces the selection.
  129. With a positive argument, turns it on.
  130. With a non-positive argument, turns it off."
  131.   (interactive "P")
  132.   (setq pending-delete-mode
  133.     (if (null arg) (not pending-delete-mode)
  134.       (> (prefix-numeric-value arg) 0)))
  135.   (if pending-delete-mode
  136.       (add-hook 'pre-command-hook 'pending-delete-pre-hook)
  137.     (remove-hook 'pre-command-hook 'pending-delete-pre-hook))
  138.   (force-mode-line-update))
  139.  
  140.  
  141. ;; Backward compatibility:
  142. ;;;###autoload
  143. (define-obsolete-function-alias 'pending-delete-on 'turn-on-pending-delete)
  144. ;;;###autoload
  145. (define-obsolete-function-alias 'pending-delete-off 'turn-off-pending-delete)
  146.  
  147. ;; FSF compatibility:
  148. ;;;###autoload
  149. (define-compatible-function-alias 'delete-selection-mode 'pending-delete-mode)
  150.  
  151. ;; Compatibility and convenience:
  152. ;;;###autoload
  153. (defalias 'pending-delete 'pending-delete-mode)
  154.  
  155.  
  156. ;; The following code used to turn the mode on unconditionally.
  157. ;; However, this is a very bad idea -- since pending-del is
  158. ;; autoloaded, (turn-on-pending-delete) is as easy to add to `.emacs'
  159. ;; as (require 'pending-del) used to be.
  160.  
  161. ;(pending-delete-on (eq pending-delete-verbose t))
  162.  
  163. (provide 'pending-del)
  164.  
  165. ;;; pending-del.el ends here
  166.